//
//  Base.m
//  superLesson
//
//  Created by dllo on 10/19/15.
//  Copyright © 2015 King. All rights reserved.
//

#import "Base.h"

@implementation Base

+ (instancetype)modelWithDic:(NSDictionary *)dic
{
    // 1. self 谁调用就是谁
    // 2. 多态: 父类的指针可以指向子类的对象
    static Base *base = nil;
    
    base = [[self alloc]init];
    [base setValuesForKeysWithDictionary:dic];
    return base;
}


// 3. 只针对model的外部操作可以放到基类

+ (NSArray<Base *> *)modelWithArr:(NSArray<NSDictionary *> *)arr
{
    NSMutableArray *sourseArr = [NSMutableArray array];
    for (NSDictionary *dic in arr) {
        Base *base = [self modelWithDic:dic];
        [sourseArr addObject:base];
    }
    return sourseArr;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key
{
    if ([key isEqualToString:@"id"]) {
        self.ID = value;
    }
}

- (id)valueForUndefinedKey:(NSString *)key
{

    return nil;
}


@end
